﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;
using Data.DBOES;

namespace Data.Controllers
{
    public class RuongMuoiNhaController : Controller<RuongMuoiNha>
    {
        public static List<RuongMuoiNha> RuongMuoiNha_Select_Distinct(string spName, string ColumnName)
        {
            Exception ex = new Exception();

            System.Data.SqlClient.SqlParameter columnName = new System.Data.SqlClient.SqlParameter("@fielName", ColumnName);
            System.Data.DataTable dt = ExecuteDataTable(spName, System.Data.CommandType.StoredProcedure, new System.Data.SqlClient.SqlParameter[] { columnName }, ref ex);


            List<RuongMuoiNha> list = new List<RuongMuoiNha>();

            if (dt == null)
                return list;

            foreach (System.Data.DataRow row in dt.Rows)
            {
                RuongMuoiNha item = new RuongMuoiNha();
                foreach (System.Data.DataColumn column in dt.Columns)
                {
                    foreach (System.Reflection.PropertyInfo property in item.GetType().GetProperties())
                    {
                        if (property.Name.ToLower() == column.ColumnName.ToLower())
                        {
                            if (row[column] != DBNull.Value)
                            {
                                property.SetValue(item, row[column], null);
                            }
                            break;
                        }
                    }
                }

                list.Add(item);
            }
            return list;
        }
    }
}
